package com.itlong.cloud.app.resource;

import com.alibaba.fastjson.JSONArray;
import com.itlong.cloud.POJO.DTO.app.old.AppOldIosDeviceListDTO;
import com.itlong.cloud.POJO.DTO.app.old.AppOldUserInfoDto;
import com.itlong.cloud.POJO.VO.app.old.AppOldAdVo;
import com.itlong.cloud.POJO.VO.app.old.AppOldDeviceVO;
import com.itlong.cloud.POJO.VO.app.old.AppOldPushVO;
import com.itlong.cloud.app.service.IAppOldHomeService;
import com.itlong.cloud.enumerate.oldapp.Message;
import com.itlong.cloud.user.app.IAppOldHomeServiceClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <desc>
 *     旧版APP的首页版块接口代理实现
 * </desc>
 *
 * @createDate 2017/11/21
 */
@RestController
public class AppOldHomeServiceResource implements IAppOldHomeServiceClient{
    @Autowired
    IAppOldHomeService iAppOldHomeService;


    /**
     * <desc>
     *     旧版APP_查询用户
     * </desc>
     * @param phoneNo
     * @return
     */
    @Override
    @RequestMapping(path = "/app/home/getOldUserDtoByPhone",method = RequestMethod.POST)
    public AppOldUserInfoDto getAppOldUserDtoByPhone(@RequestParam("phoneNo") String phoneNo){
        return  iAppOldHomeService.getAppOldUserDtoByPhone(phoneNo);
    }

    /**
     * <desc>
     *    获取通知公告.
     * </desc>
     *
     * @param  userId 用户Id
     * @param  pushAutoIndex 公告信息序号（由极光推送告知APP，App再通过此序号获取对应到公告信息）
     * @param  projectId 项目编号
     * @return 通知公告
     * @author cuiduanwu
     * @createDate 2017-12-05
     */
    @RequestMapping(path = "/app/home/getAppOldPushVO",method = RequestMethod.POST)
    public AppOldPushVO getAppOldPushVO(@RequestParam("userId") String userId,@RequestParam(value = "pushAutoIndex",required = false) String pushAutoIndex,@RequestParam("projectId") String projectId){
        return iAppOldHomeService.getAppOldPushVO(userId,pushAutoIndex,projectId);
    }

    /**
     * <desc>
     *      获取用户拥有的项目列表
     * </desc>
     *
     * @param userId
     * @return
     * @author Jiaqi.X
     * @createDate 2018/01/12
     */
    @RequestMapping(path = "/app/home/getUserProjectList",method = RequestMethod.POST)
    public List<String> getUserProjectList(@RequestParam("userId") String userId){
        return iAppOldHomeService.getUserProjectList(userId);
    }

    /**
     * <desc>
     *      获取旧APP安卓用户设备列表
     * </desc>
     *
     * @param userId 用户id
     * @param projectId 项目id
     * @return
     * @author Jiaqi.X
     * @createDate 2017/12/28
     */
    @RequestMapping(path = "/app/home/getHomeDeviceByProjectId",method = RequestMethod.POST)
    public JSONArray getHomeDeviceByProjectId(@RequestParam("userId") String userId,@RequestParam("projectId") String projectId) throws Exception{
        return iAppOldHomeService.getHomeDeviceByProjectId(userId,projectId);
    }

    /**
     * <desc>
     *      获取IOS设备列表
     * </desc>
     *
     * @param dto
     * @return
     * @author jiaqi.X
     * @createDate 2018/01/12
     */
    @RequestMapping(path = "/app/home/getIosDeviceList",method = RequestMethod.POST)
    public List<AppOldDeviceVO> getIosDeviceList(@RequestBody AppOldIosDeviceListDTO dto) throws Exception{
        return iAppOldHomeService.getIosDeviceList(dto);
    }

    /**
     * <desc>
     *    获取广告列表.
     * </desc>
     *
     * @param userId 用户Id
     * @param projectId 项目Id
     * @return 广告信息列表
     * @author cuiduanwu
     * @createDate 2017-12-05
     */
    @RequestMapping(path = "/app/home/getAppOldAd",method = RequestMethod.POST)
    public List<AppOldAdVo> getAppOldAd(@RequestParam("userId") String userId,@RequestParam("projectId") String projectId){
        return  iAppOldHomeService.getAppOldAd(userId,projectId);
    }


    /**
     * <desc>
     *      根据用户Id和用户Id获取用户项目资料列表.
     * </desc>
     *
     * @param  userId
     *  @param projectId 项目Id，若为空字符串，则查询该用户所有项目的资料列表
     * @return 项目资料列表
     * @author cuiduanwu
     * @createDate 2017-12-05
     */
    @RequestMapping(path = "/app/home/getUserProject",method = RequestMethod.POST)
    public List<Map<String, Object>> getUserProject(@RequestParam("userId") String userId,@RequestParam("projectId") String projectId){
        return iAppOldHomeService.getUserProject(userId,projectId);
    }

    /**
     * <desc>
     *     查询用户在指定项目的有权限的门禁设备信息.
     * </desc>
     *
     * @param  userId 用户Id（查询参数）
     *@param  projectId 项目编号（查询参数）
     * @param  currentPage 当前页（查询参数）
     * @param  pageSize 单页数量 （查询参数）
     * @param cardNum 软卡号
     * @param pubKey 项目公钥
     * @return 有权限的门禁设备列表
     * @author cuiduanwu
     * @createDate 2017-12-05
     */
    @RequestMapping(path = "/app/home/getUserEntranceAuthList",method = RequestMethod.POST)
    public List<AppOldDeviceVO> getUserEntranceAuthList(@RequestParam("userId")String userId,
                                                        @RequestParam("projectId")String projectId,
                                                        @RequestParam("currentPage") String currentPage,
                                                        @RequestParam("pageSize") String pageSize,
                                                        @RequestParam("cardNum")String cardNum,
                                                        @RequestParam("pubKey") String pubKey) throws Exception{
        return iAppOldHomeService.getUserEntranceAuthList(userId,projectId,currentPage,pageSize,cardNum,pubKey);
    }

    /**
     * <desc>
     * 查询用户在指定项目的有权限的电梯设备信息.
     * </desc>
     *
     * @param userId      用户Id（查询参数）
     * @param projectId   项目编号（查询参数）
     * @param currentPage 当前页（查询参数）
     * @param pageSize    单页数量 （查询参数）
     * @param cardNum     软卡号
     * @param pubKey      项目公钥
     * @return 有权限的电梯设备列表
     * @author LewisLouis
     * @createDate 2017-12-05
     */
    @Override
    @RequestMapping(path = "/app/home/getUserElevatorAuthList",method = RequestMethod.POST)
    public List<AppOldDeviceVO> getUserElevatorAuthList(@RequestParam("userId")String userId,
                                                        @RequestParam("projectId")String projectId,
                                                        @RequestParam("currentPage") String currentPage,
                                                        @RequestParam("pageSize") String pageSize,
                                                        @RequestParam("cardNum")String cardNum,
                                                        @RequestParam("pubKey") String pubKey
                                                        ) throws Exception {
        return iAppOldHomeService.getUserElevatorAuthList(userId,projectId,currentPage,pageSize,cardNum, pubKey);
    }

    /**
     * <desc>
     * 查询用户在指定项目的有权限的云对讲设备信息.
     * </desc>
     *
     * @param userId         用户Id（查询参数）
     * @param projectId      项目编号（查询参数）
     * @param currentPage    当前页（查询参数）
     * @param pageSize       单页数量 （查询参数）
     * @param cardNum        软卡号
     * @param pubKey         项目公钥
     * @param sipAddress     sip服务器地址
     * @param sipPort        sip服务器端口
     * @param userSipAccount sip账号
     * @param userSipPsd     sip密码
     * @return 有权限的云对讲设备列表
     * @author LewisLouis
     * @createDate 2017-12-05
     */
    @Override
    @RequestMapping(path = "/app/home/getUserIntercomAuthList",method = RequestMethod.POST)
    public List<AppOldDeviceVO> getUserIntercomAuthList(@RequestParam("userId")String userId,
                                                        @RequestParam("projectId")String projectId,
                                                        @RequestParam("currentPage") String currentPage,
                                                        @RequestParam("pageSize") String pageSize,
                                                        @RequestParam("cardNum")String cardNum,
                                                        @RequestParam("pubKey") String pubKey,
                                                        @RequestParam("sipAddress") String sipAddress,
                                                        @RequestParam("sipPort")  String sipPort,
                                                        @RequestParam("userSipAccount") String userSipAccount,
                                                        @RequestParam("userSipPsd") String userSipPsd) throws Exception {
        return iAppOldHomeService.getUserIntercomAuthList(userId,projectId,currentPage,pageSize,cardNum,pubKey,
                sipAddress,sipPort,userSipAccount,userSipPsd);
    }


    /**
     * <desc>
     *     旧版APP_open开门首页
     * </desc>
     * @param pushAutoIndex
     * @param phoneNo
     * @param pageSize
     * @param pageNo
     * @param projectId
     * @return
     * @throws Exception
     * *@createDate 2017/11/21
     * @author cuiduanwu
     */
    @Override
    @RequestMapping(path = "/app/open",method = RequestMethod.POST)
    public Message appOpen(@RequestParam(value = "pushAutoIndex",required = false)String pushAutoIndex,@RequestParam("phoneNo")String phoneNo,
                    @RequestParam("pageSize") Integer pageSize,@RequestParam("pageNo") Integer pageNo,
                    @RequestParam("projectId") String projectId) throws Exception{
        return iAppOldHomeService.appOpen(pushAutoIndex,phoneNo,pageSize,pageNo,projectId);
    }

    /**
     *  <desc>
     *      旧版APP_获取用户信息
     *  </desc>
     * @param phoneNo
     * @param projectId
     * @param pswd
     * @param loginDevice
     * @param token
     * @return
     * @throws Exception
     * @createDate 2017/11/27
     * @author cuiduanwu
     */
    @Override
    @RequestMapping(path = "/app/getUserInfo",method = RequestMethod.POST)
    public Message getUserInfo(@RequestParam("phoneNo")String phoneNo,@RequestParam(value = "projectId",required = false) String projectId,
                               @RequestParam(value = "pswd",required = false) String pswd,@RequestParam(value = "loginDevice",required = false) String loginDevice,@RequestParam("token") String token) throws Exception{
        return iAppOldHomeService.getUserInfo(phoneNo,projectId,pswd,loginDevice,token);
    }
    /**
     * <desc>
     *     旧版APP_home开门首页
     * </desc>
     * @param pushAutoIndex
     * @param phoneNo
     * @param pageSize
     * @param pageNo
     * @param projectId
     * @return
     * @throws Exception
     * @createDate 2017/11/27
     * @author cuiduanwu
     */
    @Override
    @RequestMapping(path = "/app/home",method = RequestMethod.POST)
    public Message appHome(@RequestParam(value = "pushAutoIndex",required = false) String pushAutoIndex,@RequestParam("phoneNo") String phoneNo,
           @RequestParam("pageSize") Integer pageSize,@RequestParam("pageNo") Integer pageNo,@RequestParam(value = "projectId",required = false) String projectId) throws Exception{
        return iAppOldHomeService.appHome(pushAutoIndex,phoneNo,pageSize,pageNo,projectId);
    }








}
